package com.monolith.jd.demo.ws.conf;

import com.monolith.jd.demo.ws.NewMessageNotifier;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;

/**
 * 2018/10/9 Create by 郭文梁
 * NewMessageNotifierConfiguration
 * 配置新消息通知websocket
 *
 * @author 郭文梁
 * @date 2018/10/9
 */
@EnableWebSocket
@Configuration
public class NewMessageNotifierConfiguration implements WebSocketConfigurer {
    private final NewMessageNotifier notifier;

    @Autowired
    public NewMessageNotifierConfiguration(NewMessageNotifier notifier) {
        this.notifier = notifier;
    }

    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        registry.addHandler(notifier, "/new-message-notifier");
    }
}
